package ar.com.angrymachine.hunter.activities;

import java.awt.Graphics;
import java.awt.Rectangle;

import ar.com.angrymachine.hunter.Game;
import ar.com.angrymachine.hunter.GraphicStyles;
import ar.com.angrymachine.hunter.Locale;
import ar.com.angrymachine.hunter.gameplay.Chest;

public class ChestActivity extends IncrementalActivity
{
    private Chest chest;
    private int level;
    
    public ChestActivity(Chest chest)
    {
        this.chest = chest;
    }
    
    public int getLevel()
    {
        return level;
    }
        
    public String getDescription()
    {
        if(isCompleted())
        {
            return chest.name;
        }
        else
        {
            return Locale.percentageLabel(chest.name, currentTime, getCompletionTime());
        }
    }

    public String getActionText()
    {
        if(isCompleted())
        {
            return Locale.OPENED;
        }
        else
        {
            if(isRunning())
            {
                return Locale.OPENING;
            }
            else
            {
                return Locale.UNLOCK;
            }
        }
    }    

    public void paint(Graphics g, Rectangle activityArea)
    {
        if(isCompleted())
        {
            GraphicStyles.paintDefaultActivity(g, this, activityArea, chest.treasure.icon);
        }
        else
        {
            GraphicStyles.paintDefaultActivity(g, this, activityArea, chest.icon);
        }
    }

    public void onFinished()
    {
        // drop treasure
        if(chest.treasure != null)
        {
        	Game.current.currentLevel.addActivity(this, new TreasureActivity(chest.treasure));
        }
    }

    protected int getCompletionTime()
    {
        return chest.treasure.openTime;
    }

    protected int getFinalIncrement(int delta)
    {
        return (int)(delta * Game.current.player.getDisarmPower());
    }

    protected boolean onCompletion()
    {
        return true;
    }
}
